import 'package:dio/dio.dart';
import '../interceptors/simple_error_interceptor.dart';

/// 简单的Dio配置类
class SimpleDioConfig {
  static Dio createDio() {
    final dio = Dio();
    
    // 基础配置
    dio.options = BaseOptions(
      baseUrl: 'https://jsonplaceholder.typicode.com',
      connectTimeout: const Duration(seconds: 10),
      receiveTimeout: const Duration(seconds: 10),
      sendTimeout: const Duration(seconds: 10),
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
      },
    );
    
    // 添加错误拦截器（使用ToastService）
    dio.interceptors.add(SimpleErrorInterceptor());
    
    // 添加日志拦截器（用于调试）
    dio.interceptors.add(LogInterceptor(
      requestHeader: true,
      requestBody: true,
      responseHeader: false,
      responseBody: true,
      error: true,
      logPrint: (object) => print('🌐 Dio: $object'),
    ));
    
    print('✅ Dio实例已创建，包含错误拦截器');
    return dio;
  }
}
